package com.khalil.kkadmin.kb.repository;

import com.khalil.kkadmin.infrastructure.jpa.KkJpaRepository;
import com.khalil.kkadmin.kb.domain.KbDocumentDir;
import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface KbDocumentDirRepository extends KkJpaRepository<KbDocumentDir, Long> {
    List<KbDocumentDir> findByParentIdOrderByOrderNum(Long parentId);

    @Query(value = "select max(orderNum) from KbDocumentDir where parentId = ?1")
    Integer findMaxOrderNumByParentId(Long parentId);

    @Transactional
    @Modifying
    @Query(value = "update KbDocumentDir set orderNum = ?2 where id = ?1")
    void updateOrderNum(Long id, Integer orderNum);
}
